using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;

namespace PotonCapture
{
    public partial class ConfirmForm : Form
    {
        public string FileName
        {
            get { return _fileNameText.Text; }
            set { _fileNameText.Text = value; }
        }

        public string OldPath
        {
            get { return _oldPathText.Text; }
            set { _oldPathText.Text = value; }
        }

        private string _newPath;

        public string NewPath
        {
            get { return _newPath; }
            set { _newPath = value; }
        }

        private bool _overwrite;

        public bool Overwrite
        {
            get { return _overwrite; }
            set { _overwrite = value; }
        }
	
        public Image ImageSample
        {
            get { return _imageBox.Image; }
            set { _imageBox.Image = value; }
        }

        public Size ImageSampleSize
        {
            get { return _imageBox.ClientSize; }
        }

        public ConfirmForm()
        {
            InitializeComponent();
        }

        private void _okButton_Click(object sender, EventArgs e)
        {
            string oldName = Path.GetFileNameWithoutExtension(_oldPathText.Text);
            if (Path.GetExtension(_fileNameText.Text) == Path.GetExtension(_oldPathText.Text))
            {
                _fileNameText.Text = Path.GetFileNameWithoutExtension(_fileNameText.Text);
            }

            if (oldName != _fileNameText.Text && _fileNameText.Text.Length > 0)
            {
                string newFilePath = Path.Combine(Path.GetDirectoryName(_oldPathText.Text), _fileNameText.Text) + Path.GetExtension(_oldPathText.Text);
                if (File.Exists(newFilePath))
                {
                    if (MessageBox.Show(this, "Overwrite file?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
                    {
                        return;
                    }
                    _overwrite = true;
                }
                _newPath = newFilePath;
                DialogResult = DialogResult.OK;
            }
            Close();
        }
    }
}